﻿using System;
using Microsoft.Xna.Framework;

namespace GP2D3D_Homework3_RickBeijer_JeroenPasman
{
    public class ExerciseManager
    {
        public static Vector3 Exercise1A()
        {
            Vector3 v1 = new Vector3( 1, 2, 3 );
            Matrix m1 = new Matrix( 1, 2, 3, 0,
                                    6, 5, 4, 0,
                                    7, 8, 9, 0,
                                    0, 0, 0, 0);

            Vector3 solution = Vector3.Transform( v1, m1 );

            return solution;
        }

        public static Matrix Exercise1B()
        {
            Matrix m1 = new Matrix( 5, 0, 0, 0,
                                   -2, 0, 0, 0,
                                    1, 0, 0, 0,
                                    0, 0, 0, 0 );
            Matrix m2 = new Matrix( -1, 3, 2, 0,
                                     0, 0, 0, 0,
                                     0, 0, 0, 0,
                                     0, 0, 0, 0 );

            Matrix solution = m1 * m2;
            
            return solution;
        }

        public static Matrix Exercise2()
        {
            Matrix m1 = Matrix.CreateScale( 3 );
            Matrix m2 = Matrix.CreateRotationX( MathHelper.ToRadians( 45 ) );
            Matrix m3 = Matrix.CreateScale( 2, 1, 2 );

            Matrix solution = m3 * m2 * m1;

            return solution;
        }

        public static Vector4 Exercise3()
        {
            Vector4 a = new Vector4( 0.2f, -1.0f, 2.2f, 1.0f );

            Vector4 solution = Vector4.Transform( a, Exercise2() );

            return solution;
        }

        public static Matrix Exercise4()
        {
            Matrix rotate = Matrix.CreateRotationZ( MathHelper.ToRadians( 30 ) );
            
            Matrix m1 = new Matrix( 0.2f, 0, 0, 0,
                                   -1.0f, 0, 0, 0,
                                    2.2f, 0, 0, 0,
                                    1.0f, 0, 0, 0 );

            Matrix solution = m1 * Exercise2();
            
            return solution;
        }

        public static string Exercise5()
        {
            Matrix m1 = new Matrix( 0.2f, 0, 0, 0,
                                   -1.0f, 0, 0, 0,
                                    2.2f, 0, 0, 0,
                                    1.0f, 0, 0, 0 );
            Matrix transformation = Exercise2();
            Matrix transposedTransformation = Matrix.Transpose( transformation );

            Matrix solution = transposedTransformation * m1;

            string solutionDescription = "A transpose action mirrors a matrix around its diagonal. That " + Environment.NewLine +
                                         "means that a matrix M(r,c), where r is the row and c is the column," + Environment.NewLine +
                                         "will result in M(c,r) when transposed. A horizontal matrix will be" + Environment.NewLine + 
                                         "flipped to become a vertical matrix, and the other way around." + Environment.NewLine + 
                                         Environment.NewLine +
                                         "Since vector a was (0.2, -1.0, 2.2, 1.0), it is only logical that" + Environment.NewLine +
                                         "when transposed, it will form vector b:" + Environment.NewLine +
                                         "( 0.2," + Environment.NewLine +
                                         " -1.0," + Environment.NewLine +
                                         "  2.2," + Environment.NewLine + 
                                         "  1.0 ).";

            return solutionDescription;
        }
    }
}